﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using AutoLoL.Entities;
using System.Windows;

namespace AutoLoL.Converters
{
    public class SummonerSpellToVisibilityConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool invert = false;
            if (parameter != null)
            {
                bool.TryParse(parameter.ToString(), out invert);
            }

            Visibility result = Visibility.Collapsed;

            if (values != null && values.Length == 2 && values[0] != null && values[1] != null && values[0] is SummonerSpell && values[1] is SummonerSpell[])
            {
                if (((SummonerSpell[])values[1]).Contains((SummonerSpell)values[0]))
                {
                    result = Visibility.Visible;
                }
            }
            else
            {
                return Visibility.Collapsed;
            }

            if (invert)
            {
                if (result == Visibility.Collapsed)
                {
                    return Visibility.Visible;
                }

                return Visibility.Collapsed;
            }

            return result;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
